package vn.orderonline.com.core.business.acountadmin;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import vn.orderonline.com.core.business.dto.AdminDto;
import vn.orderonline.core.commons.utils.StringUtils;
import vn.orderonline.core.dao.AdminDao;
import vn.orderonline.core.dao.entity.Admin;
import vn.orderonline.core.dao.entity.Role;

@Service
@Transactional
public class AccounAdminManager implements IAccountAdminManager {
	
	@Autowired
	private AdminDao adminDao;

	@Override
	public Boolean checkExistedAccountAdmin(String username, String password) {
		if (!StringUtils.isNullOrEmpty(username) || !StringUtils.isNullOrEmpty(password)) {
			if (adminDao.checkExistedAccount(username.trim(), password.trim())) {
				return true;
			}
		}
		return false;
	}

	@Override
	public AdminDto getAdminByAdminLoginId(String username) {
		AdminDto adminDto = null;
		if (!StringUtils.isNullOrEmpty(username)) {
			Object[] obj = adminDao.getAdminByAdminLoginId(username);
			Admin admin = null;
			Role role = null;
			if (obj != null) {
				adminDto = new AdminDto();
				admin = (Admin) obj[0];
				role = (Role) obj[1];
				adminDto.setAdminLoginId(admin.getAdminLoginId());
				adminDto.setAdminPassword(admin.getAdminPassword());
				adminDto.setRoleName(role.getRoleName());
			}
		}
		return adminDto;
	}
	
}
